package com.ruoyi.operation.dubbo;

import com.ruoyi.common.satoken.utils.LoginHelper;
import com.ruoyi.operation.api.RemoteExecuteSidService;
import com.ruoyi.operation.api.vo.ServiceMap;
import com.ruoyi.operation.domain.bo.TSqltoolBo;
import com.ruoyi.operation.service.ITSqltoolService;
import com.ruoyi.system.api.model.LoginUser;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author Zzneko
 * @Date 2025/7/15 13:46
 * @Descprition
 **/
@DubboService
@RequiredArgsConstructor
public class RemoteExecuteSidServiceImpl implements RemoteExecuteSidService {

    private final ITSqltoolService itSqltoolService;
    @Override
    public List<ServiceMap> getServiceMap(String service) {
        //目前暂时就一个需要支持审批功能
        LoginUser user = LoginHelper.getLoginUser();
        if("sql_execute_audit".equals(service)){
            TSqltoolBo bo = new TSqltoolBo();
            bo.setCreateBy(user.getUsername());
            return itSqltoolService.queryList(bo).stream()
                .map(x->{
                    ServiceMap map = new ServiceMap();
                    map.setServiceId(x.getId());
                    map.setServiceName(x.getToolname());
                    return map;
                }).collect(Collectors.toList());
        }else{
            return null;
        }
    }
}
